package com.neusoft.controller;

import com.neusoft.base.BaseController;
import com.neusoft.model.CommentSearch;
import com.neusoft.po.Comment;
import com.neusoft.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 评论请求控制器
 *
 * @author Lucifer
 * @since 2021/5/16 17:45
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论接口")
public class CommentController extends BaseController {

    @Resource
    private CommentService commentService;

    @PostMapping("/page")
    @ApiOperation("获取所有评论，管理员界面")
    public Object page(@RequestBody CommentSearch commentSearch) {
        return commentService.page(commentSearch);
    }

    @GetMapping
    @ApiOperation("获取单个评论消息")
    @ApiImplicitParam(value = "评论ID", name = "id", required = true)
    public Comment get(Integer id) {
        return commentService.getById(id);
    }

    @PostMapping
    @ApiOperation("单条评论保存")
    public Integer save(@RequestBody Comment comment) {
        commentService.save(comment);
        return comment.getId();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("单个评论删除（新增，修改同）")
    public Integer delete(@PathVariable("id") Integer id) {
        commentService.deleteById(id);
        return id;
    }

    @PostMapping("/examine")
    @ApiOperation("审核通过")
    public Integer examine(@RequestBody Integer[] ids) {
        return commentService.examine(ids);
    }

}